package exam.test14;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Endstart
 * Date: 2020-12-08
 * Time: 9:07
 */
public class BankAccount {
    private String id;
    private double balance;

    public BankAccount(String id) {
        this.id = id;
    }

    public void deposit(double amount) {
        balance += amount;
    }

    public void withdraw(double amount) {
        balance -= amount;
    }

    @Override
    public String toString() {
        return id + ": " + balance;
    }

    public void transfer(BankAccount account, double amount) {
        if (balance < 5 || amount <= 0) {
            System.out.println("nothing");
            return;
        }
        withdraw(5);
        double amountTmp = amount;
        if (balance < amount) {
            amountTmp = balance;
        }
        withdraw(amountTmp);
        account.deposit(amountTmp);
        System.out.print(toString());
        System.out.print("  " + account.toString() + "\n");
    }

    public static void main(String[] args) {
        BankAccount bensom = new BankAccount("bensom");
        bensom.deposit(90.00);

        BankAccount martin = new BankAccount("martin");
        martin.deposit(25.00);

        bensom.transfer(martin, 20);
        bensom.transfer(martin, 10);
        bensom.transfer(martin, -1);
        martin.transfer(bensom, 39);
        martin.transfer(bensom, 50);
        martin.transfer(bensom, 1);

        bensom.transfer(martin, 88);
        bensom.transfer(martin, 1);

    }

}
